import axios from "axios";
import store from '../store'

type Method = 'get' | 'post' | 'GET' | 'POST';

interface AxiosRequestConfig {
    url: string,
    method: Method,
    data?: any,
    params?: any
}

axios.interceptors.request.use(
    config =>{
        store.commit('VUEX_MU_LOADING',true);
        return config
    },
    err =>{
        return Promise.reject(err)
    }
)

axios.interceptors.response.use(
    response => {
        store.commit('VUEX_MU_LOADING',false);
        return response.data;
    },
    error => {
        return Promise.reject(error) // 返回接口返回的错误信息
    }
);


export default function request(data : AxiosRequestConfig) {
    const { url, method } = data;
    return axios({
        responseType: "json",
        url,
        method,
        data : data.data
    })
}

